//
//  LSRequestManager.h
//  AFNetworkingDemo
//
//  Created by Leon on 16/2/2.
//  Copyright © 2016年 上海指旺信息科技有限公司. All rights reserved.
//

#import <Foundation/Foundation.h>

#define HUOBI(url)        [NSString stringWithFormat:@"http://172.16.20.15/%@",(url)]
#define GOOGLE(url)        [NSString stringWithFormat:@"http://172.16.20.101:55400/%@",(url)]
static NSString *BASE_URL = @"http://172.16.20.15/";

#define MARKET(url)  [NSString stringWithFormat:@"http://172.16.20.101:55000/%@",(url)]
#define Success [responseData[@"ret"]integerValue] == 0
/**
 *  请求成功回调
 *
 *  @param responseData
 */
typedef void (^ReqSuccessBlock)(NSDictionary *responseData);
/**
 *  下载成功回调
 *
 *  @param response
 */
typedef void (^DownloadSuccessBlock)(NSURLResponse *response, NSURL *filePath);
/**
 *  请求失败回调
 *
 *  @param error
 */
typedef void (^ReqFailureBlock)(NSError *error);


@interface LSRequestManager : NSObject

/**
 *  单例模式
 */
+ (instancetype)sharedInstance;

/**
 *  GET请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)getRequestWithURL:(NSString *)url
                   params:(NSDictionary *)params
                  success:(ReqSuccessBlock)successBlock
                  failure:(ReqFailureBlock)failBlock
                  showHUD:(BOOL)showHud;

/**
 *  GET请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)getRequestWithURL:(NSString *)url
                   params:(NSDictionary *)params
                  success:(ReqSuccessBlock)successBlock
                  failure:(ReqFailureBlock)failBlock;




/**
 *  DELETE请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)deleteRequestWithURL:(NSString *)url
                      params:(NSDictionary *)params
                     success:(ReqSuccessBlock)successBlock
                     failure:(ReqFailureBlock)failBlock
                     showHUD:(BOOL)showHud;

/**
 *  POST 请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)postRequestWithURL:(NSString *)url
                    params:(NSDictionary *)params
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock
                   showHUD:(BOOL)showHud;

/**
 *  POST 请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)postRequestWithURL:(NSString *)url
                    params:(NSDictionary *)params
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock;
/**
 *  PUT 请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)putRequestWithURL:(NSString *)url
                    params:(NSDictionary *)params
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock
                   showHUD:(BOOL)showHud;

/**
 *  POST 请求
 *
 *  @param url          url
 *  @param params       param
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)putRequestWithURL:(NSString *)url
                    params:(NSDictionary *)params
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock;
/**
 *  文件上传
 *
 *  @param url          url
 *  @param params       param
 *  @param files        文件数组
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)uploadFilesWithURL:(NSString *)url
                    params:(NSDictionary *)params
                     files:(NSArray *)files
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock
                   showHUD:(BOOL)showHud;
/**
 *  文件上传
 *
 *  @param url          url
 *  @param params       param
 *  @param files        文件数组
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)uploadFilesWithURL:(NSString *)url
                    params:(NSDictionary *)params
                     files:(NSArray *)files
                   success:(ReqSuccessBlock)successBlock
                   failure:(ReqFailureBlock)failBlock;


/**
 *  文件下载
 *
 *  @param url          文件地址
 *  @param filname      文件重命名
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 *  @param showHud      显示 hud
 */
+ (void)downloadFileWithURL:(NSURL *)url
                   filename:(NSString *)filname
                    success:(DownloadSuccessBlock)successBlock
                    failure:(ReqFailureBlock)failBlock
                    showHUD:(BOOL)showHud;

/**
 *  文件下载
 *
 *  @param url          文件地址
 *  @param filname      文件重命名
 *  @param successBlock 成功回调
 *  @param failBlock    失败回调
 */
+ (void)downloadFileWithURL:(NSURL *)url
                   filename:(NSString *)filname
                    success:(DownloadSuccessBlock)successBlock
                    failure:(ReqFailureBlock)failBlock;


+ (void)downloadDataWithURL:(NSURL *)url
                    success:(ReqSuccessBlock)successBlock
                    failure:(ReqFailureBlock)failBlock;

@end



/**
 *  文件数据封装模型
 */
@interface UploadFormData : NSObject

@property (nonatomic, strong) NSData *data;  /**< 文件数据 */

@property (nonatomic, copy) NSString *name; /**< 参数名 */

@property (nonatomic, copy) NSString *filename; /**< 文件名 */

@property (nonatomic, copy) NSString *mimeType; /**< 文件类型 */

@end
